﻿namespace ACCOUNTING
{
    using ACCOUNTING.LVY.Business;
    using ACCOUNTING.My;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    [StandardModule]
    internal sealed class SearchModule
    {
        public static string GetNamThang(string strNamThang = "")
        {
            MyProject.Forms.Frm_NamThang.ShowDialog();
            return MyProject.Forms.Frm_NamThang.NamThang;
        }

        public static string SearchChungTuBanHang(string pKhoaNotShow)
        {
            MyProject.Forms.Frm_TimPhieuBanHang.Dispose();
            MyProject.Forms.Frm_TimPhieuBanHang.pKhoaNotShow = pKhoaNotShow;
            MyProject.Forms.Frm_TimPhieuBanHang.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchChungTuMuaHang(bool isTrongNuoc = true)
        {
            if (isTrongNuoc)
            {
                MyProject.Forms.Frm_TimPhieuMuaHangTrongNuoc.Dispose();
                MyProject.Forms.Frm_TimPhieuMuaHangTrongNuoc.ShowDialog();
                return modGeneral.H_VALUE;
            }
            MyProject.Forms.Frm_TimPhieuMuaHangNuocNgoai.Dispose();
            MyProject.Forms.Frm_TimPhieuMuaHangNuocNgoai.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchContact(string strMa = "")
        {
            clsDMHopDong dong = new clsDMHopDong();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = dong.SearchByCode(strMa);
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 hợp đồng", "") + "|" + modGeneral.Tranlated("Số hợp đồng", "") + "|" + modGeneral.Tranlated("Ng\x00e0y hợp đồng", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = dong.ShowList();
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchCosting(string strMa = "")
        {
            clsDMKhoanMucChiPhi phi = new clsDMKhoanMucChiPhi();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = phi.SearchByCode(strMa, "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 chi ph\x00ed", "") + "|" + modGeneral.Tranlated("Chi ph\x00ed", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = phi.ShowList();
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static object SearchDanhMuc(modGeneral.ListDanhMuc DanhMuc, string strMa = "", string strKeyFilter = "", string strFieldNameFilter = "")
        {
            string str = "";
            switch (((int) DanhMuc))
            {
                case 1:
                    return SearchNhomHangHoa(strMa);

                case 2:
                    return str;

                case 3:
                    return str;
            }
            return str;
        }

        public static string SearchDanhSachKhachHangTamUng(bool isTrongNuoc = true)
        {
            if (isTrongNuoc)
            {
                MyProject.Forms.FrmTimKhachHangTamUng.Dispose();
                MyProject.Forms.FrmTimKhachHangTamUng.LoaiKhachHang = "TN";
                MyProject.Forms.FrmTimKhachHangTamUng.ShowDialog();
                return modGeneral.H_VALUE;
            }
            MyProject.Forms.FrmTimKhachHangTamUng.Dispose();
            MyProject.Forms.FrmTimKhachHangTamUng.LoaiKhachHang = "NN";
            MyProject.Forms.FrmTimKhachHangTamUng.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchDanhSachTraTruocNguoiBan(bool isTrongNuoc = true, string pKhoaNotShow = "")
        {
            if (isTrongNuoc)
            {
                MyProject.Forms.FrmTimTraTruocNguoiBan.Dispose();
                MyProject.Forms.FrmTimTraTruocNguoiBan.LoaiKhachHang = "TN";
                MyProject.Forms.FrmTimTraTruocNguoiBan.pKhoaNotShow = pKhoaNotShow;
                MyProject.Forms.FrmTimTraTruocNguoiBan.ShowDialog();
                return modGeneral.H_VALUE;
            }
            MyProject.Forms.FrmTimTraTruocNguoiBan.Dispose();
            MyProject.Forms.FrmTimTraTruocNguoiBan.LoaiKhachHang = "NN";
            MyProject.Forms.FrmTimTraTruocNguoiBan.pKhoaNotShow = pKhoaNotShow;
            MyProject.Forms.FrmTimTraTruocNguoiBan.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchDepartment(string strMa = "")
        {
            clsDMDonViBoPhan phan = new clsDMDonViBoPhan();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = phan.SearchByCode(strMa, "", "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 đơn vị", "") + "|" + modGeneral.Tranlated("T\x00ean đơn vị", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = phan.ShowList("", "");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchDieuKhoan(string strMa = "")
        {
            ClsDMDieuKhoanBaoGia gia = new ClsDMDieuKhoanBaoGia();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = gia.SearchByCode(strMa, "", "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 kho", "") + "|" + modGeneral.Tranlated("T\x00ean kho", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = gia.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchDoiTuong(string strCode = "", string strLoaiDoiTuong = "", string strConditions = "")
        {
            clsDMDoiTuong tuong = new clsDMDoiTuong();
            string str = "";
            if (strCode.Trim() != "")
            {
                str = tuong.SearchByCode(strCode, strLoaiDoiTuong);
            }
            if (str.Trim() != "")
            {
                return str;
            }
            MyProject.Forms.Frm_TimDoiTuong.Dispose();
            if (strLoaiDoiTuong.Trim() == "")
            {
                MyProject.Forms.Frm_TimDoiTuong.LoaiDoiTuong = modGeneral.TypeObjects.TatCa;
            }
            else
            {
                switch (strLoaiDoiTuong)
                {
                    case "C":
                    case "CS":
                        MyProject.Forms.Frm_TimDoiTuong.LoaiDoiTuong = modGeneral.TypeObjects.KhachHang;
                        break;

                    case "S":
                    case "SC":
                        MyProject.Forms.Frm_TimDoiTuong.LoaiDoiTuong = modGeneral.TypeObjects.NhaCungCap;
                        break;

                    case "E":
                        MyProject.Forms.Frm_TimDoiTuong.LoaiDoiTuong = modGeneral.TypeObjects.NhanVien;
                        break;

                    case "B":
                        MyProject.Forms.Frm_TimDoiTuong.LoaiDoiTuong = modGeneral.TypeObjects.NganHang;
                        break;
                }
            }
            MyProject.Forms.Frm_TimDoiTuong.Code = strCode;
            MyProject.Forms.Frm_TimDoiTuong.SourceTable = tuong.ShowList(strLoaiDoiTuong, "");
            MyProject.Forms.Frm_TimDoiTuong.ShowDialog();
            return MyProject.Forms.Frm_TimDoiTuong.ValueReturn;
        }

        public static object SearchDoiTuongThue(string strTen = "", string strMaSoThue = "", string strDiaChi = "", string pAction = "")
        {
            MyProject.Forms.Frm_DoiTuongThue.TenDoiTuong = strTen;
            MyProject.Forms.Frm_DoiTuongThue.MaSoThue = strMaSoThue;
            MyProject.Forms.Frm_DoiTuongThue.DiaChi = strDiaChi;
            MyProject.Forms.Frm_DoiTuongThue.Action = pAction;
            MyProject.Forms.Frm_DoiTuongThue.ShowDialog();
            return MyProject.Forms.Frm_DoiTuongThue.ValueReturn;
        }

        public static string[] SearchDVT(string pKhoaHangHoa, object pObjVS, int nRow, int nCol, string pValue)
        {
            DataTable listDonViTinh = new clsDMHangHoa().GetListDonViTinh(pKhoaHangHoa);
            if (listDonViTinh == null)
            {
                return null;
            }
            if (listDonViTinh.Rows.Count < 1)
            {
                return null;
            }
            return LVYModule.ShowMultiDropDownBySource(RuntimeHelpers.GetObjectValue(pObjVS), nRow, nCol, listDonViTinh, 10, 0, pValue, "");
        }

        public static double SearchGiaBan(string pKhoaLoaiGia, string pKhoaHangHoa)
        {
            clsGiaBan ban = new clsGiaBan();
            DataTable hangHoa = new clsDMHangHoa().GetHangHoa(pKhoaHangHoa);
            return ban.GetGiaBan(pKhoaHangHoa, pKhoaLoaiGia);
        }

        public static string[] SearchGoodsInStock(string NamThang, string KhoaKho = "", string KhoaLoaiGia = "", bool WasLoad = true)
        {
            if (!WasLoad)
            {
                MyProject.Forms.Frm_TimHangTonKho.WasLoadData = false;
            }
            MyProject.Forms.Frm_TimHangTonKho.NamThang = NamThang;
            MyProject.Forms.Frm_TimHangTonKho.KhoaKho = KhoaKho;
            MyProject.Forms.Frm_TimHangTonKho.LoaiGia = KhoaLoaiGia;
            MyProject.Forms.Frm_TimHangTonKho.ShowDialog();
            return MyProject.Forms.Frm_TimHangTonKho.ValueReturn;
        }

        public static string SearchHangHoa(string strCode = "", string strStockID = "", string strConditions = "")
        {
            clsDMHangHoa hoa = new clsDMHangHoa();
            MyProject.Forms.Frm_TimHangHoa.strConditions = strConditions;
            MyProject.Forms.Frm_TimHangHoa.ValueReturn = "";
            MyProject.Forms.Frm_TimHangHoa.MaHang = strCode;
            MyProject.Forms.Frm_TimHangHoa.ShowDialog();
            return MyProject.Forms.Frm_TimHangHoa.ValueReturn;
        }

        public static string SearchThanhPham(string strCode = "")
        {
            clsDMHangHoa hoa = new clsDMHangHoa();
            MyProject.Forms.Frm_TimThanhPham.strConditions = "";
            MyProject.Forms.Frm_TimThanhPham.ValueReturn = "";
            MyProject.Forms.Frm_TimThanhPham.MaHang = strCode;
            MyProject.Forms.Frm_TimThanhPham.ShowDialog();
            return MyProject.Forms.Frm_TimThanhPham.ValueReturn;
        }

        public static string SearchHangSanXuat(string strMa = "")
        {
            clsDMHangSanXuat xuat = new clsDMHangSanXuat();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = xuat.SearchByCode(strMa);
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = xuat.ShowList("", "");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static object SearchKhaiBaoThue(string strPhuongThuc = "", string strKyHieu = "", string strSoHoaDon = "", string strNgayHoaDon = "", string strTen = "", string strMaSoThue = "", string strDiaChi = "", string strDienGiaiMatHang = "", string pAction = "", string strKhoaDoiTuongThue = "")
        {
            MyProject.Forms.Frm_KhaiBaoThue.TenDoiTuong = strTen;
            MyProject.Forms.Frm_KhaiBaoThue.MaSoThue = strMaSoThue;
            MyProject.Forms.Frm_KhaiBaoThue.DiaChi = strDiaChi;
            MyProject.Forms.Frm_KhaiBaoThue.Action = pAction;
            MyProject.Forms.Frm_KhaiBaoThue.KyHieu = strKyHieu;
            MyProject.Forms.Frm_KhaiBaoThue.SoHoaDon = strSoHoaDon;
            MyProject.Forms.Frm_KhaiBaoThue.NgayHoaDon = strNgayHoaDon;
            MyProject.Forms.Frm_KhaiBaoThue.DienGiaiMatHang = strDienGiaiMatHang;
            MyProject.Forms.Frm_KhaiBaoThue.PhuongThuc = strPhuongThuc;
            MyProject.Forms.Frm_KhaiBaoThue.KhoaDoiTuongThue = strKhoaDoiTuongThue;
            MyProject.Forms.Frm_KhaiBaoThue.ShowDialog();
            return MyProject.Forms.Frm_KhaiBaoThue.ValueReturn;
        }

        public static string SearchLoaiKhachHang(string strCode = "")
        {
            clsDMLoaiKhachHang hang = new clsDMLoaiKhachHang();
            if (strCode.Trim() != "")
            {
            }
            MyProject.Forms.Frm_TimHangHoa.ShowDialog();
            return MyProject.Forms.Frm_TimHangHoa.ValueReturn;
        }

        public static string SearchNhomHangHoa(object strMa)
        {
            clsDMNhomHangHoa hoa = new clsDMNhomHangHoa();
            string str = hoa.SearchByCode(Conversions.ToString(strMa), "", "");
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = hoa.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchPhieuChiTienThua(bool isTrongNuoc = true, string pKhoaNotShow = "")
        {
            if (isTrongNuoc)
            {
                MyProject.Forms.Frm_TimPhieuChiTienThua.Dispose();
                MyProject.Forms.Frm_TimPhieuChiTienThua.LoaiKhachHang = "TN";
                MyProject.Forms.Frm_TimPhieuChiTienThua.pKhoaNotShow = pKhoaNotShow;
                MyProject.Forms.Frm_TimPhieuChiTienThua.ShowDialog();
                return modGeneral.H_VALUE;
            }
            MyProject.Forms.Frm_TimPhieuChiTienThua.Dispose();
            MyProject.Forms.Frm_TimPhieuChiTienThua.LoaiKhachHang = "NN";
            MyProject.Forms.Frm_TimPhieuChiTienThua.pKhoaNotShow = pKhoaNotShow;
            MyProject.Forms.Frm_TimPhieuChiTienThua.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchPhieuThuTienThua(bool isTrongNuoc = true)
        {
            if (isTrongNuoc)
            {
                MyProject.Forms.Frm_TimPhieuThuTienThua.Dispose();
                MyProject.Forms.Frm_TimPhieuThuTienThua.LoaiKhachHang = "TN";
                MyProject.Forms.Frm_TimPhieuThuTienThua.ShowDialog();
                return modGeneral.H_VALUE;
            }
            MyProject.Forms.Frm_TimPhieuThuTienThua.Dispose();
            MyProject.Forms.Frm_TimPhieuThuTienThua.LoaiKhachHang = "NN";
            MyProject.Forms.Frm_TimPhieuThuTienThua.ShowDialog();
            return modGeneral.H_VALUE;
        }

        public static string SearchPhuTungTaiSan(string strMa = "")
        {
            clsDM_PhuTungTaiSan san = new clsDM_PhuTungTaiSan();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = san.SearchByCode(strMa, "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 phụ t\x00f9ng", "") + "|" + modGeneral.Tranlated("T\x00ean phụ t\x00f9ng", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = san.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchProduct(string strMa = "")
        {
            clsDMSanPhamCongViec viec = new clsDMSanPhamCongViec();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = viec.SearchByCode(strMa, "", "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 sản phẩm", "") + "|" + modGeneral.Tranlated("T\x00ean sản phẩm", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = viec.ShowList("", "");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchQuocGia(string strCode = "")
        {
            clsDMQuocGia gia = new clsDMQuocGia();
            if (strCode.Trim() != "")
            {
            }
            MyProject.Forms.Frm_TimQuocGia.ShowDialog();
            return MyProject.Forms.Frm_TimQuocGia.ValueReturn;
        }

        public static string SearchStore(string strMa = "")
        {
            clsDMKho kho = new clsDMKho();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = kho.SearchByCode(strMa, "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 kho", "") + "|" + modGeneral.Tranlated("T\x00ean kho", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = kho.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchDoiTuongTapHopChiPhi(string strMa = "")
        {
            clsDMDoiTuongTapHopChiPhi dt = new clsDMDoiTuongTapHopChiPhi();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = dt.SearchByCode(strMa, "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3", "") + "|" + modGeneral.Tranlated("T\x00ean", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = dt.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }      

        public static string SearchTaiKhoan(string AccountNumber = "", string strKeyFilter = "", string strFieldNameFilter = "", string strCondition = "", string SoTaiKhoan = "")
        {
            clsDMTaiKhoan khoan = new clsDMTaiKhoan();
            string str = "";
            if (AccountNumber.Trim() != "")
            {
                str = khoan.SearchByCode(AccountNumber, strKeyFilter, strFieldNameFilter, strCondition);
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = true;
                MyProject.Forms.Frm_TimDanhMuc.Code = AccountNumber;
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = khoan.ShowList(strKeyFilter, strFieldNameFilter, strCondition, SoTaiKhoan);
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }

        public static string SearchViTri(string strMa = "")
        {
            clsDMViTri tri = new clsDMViTri();
            string str = "";
            if (strMa.ToString().Trim() != "")
            {
                str = tri.SearchByCode(strMa, "");
            }
            if (str.Trim() == "")
            {
                MyProject.Forms.Frm_TimDanhMuc.Dispose();
                MyProject.Forms.Frm_TimDanhMuc.DanhMucTaiKhan = false;
                MyProject.Forms.Frm_TimDanhMuc.TitleOfCollumn = "Khoa|" + modGeneral.Tranlated("M\x00e3 vị tr\x00ed", "") + "|" + modGeneral.Tranlated("T\x00ean vị tr\x00ed", "");
                MyProject.Forms.Frm_TimDanhMuc.SourceTable = tri.ShowList("");
                modGeneral.H_VALUE = "";
                MyProject.Forms.Frm_TimDanhMuc.ShowDialog();
                str = modGeneral.H_VALUE;
            }
            return str;
        }
    }
}

